package test.eu.dominicum.ft.pd.boundary;

import eu.dominicum.ft.pd.FantasyTour;
import eu.dominicum.ft.pd.boundary.FantasyTourManagement;
import eu.dominicum.ft.pd.boundary.ejb.FantasyTourManagementEJB;
import eu.dominicum.ft.pd.mao.MakeFantasyTourMAO;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.ejb.EJB;
import java.util.List;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

/**
 * A unit test that executes all fixtures and popplates a local datastore on success.
 *
 * @author Harry Klerks
 * @since 2013M1
 */
@RunWith(Arquillian.class)
public class FantasyTourFixture {

    @EJB
    FantasyTourManagement boundary;

    @Deployment
    public static JavaArchive createDeployment() {

        return ShrinkWrap.create(JavaArchive.class)
                .addClasses(FantasyTourManagementEJB.class, FantasyTourManagement.class)
                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    }

    @Test
    public void allFixture() {

        //Making the Fantasy Tour 2011
        MakeFantasyTourMAO mao2011 = new MakeFantasyTourMAO();
        mao2011.setName("La Poule du Tour de France 2011");
        FantasyTour fantasyTour2011 = boundary.makeFantasyTour(mao2011);
        //Making the Fantasy Tour 2012
        MakeFantasyTourMAO mao2012 = new MakeFantasyTourMAO();
        mao2012.setName("La Poule du Tour de France 2012");
        FantasyTour fantasyTour2012 = boundary.makeFantasyTour(mao2012);
        //Making the Fantasy Tour 2013
        MakeFantasyTourMAO mao2013 = new MakeFantasyTourMAO();
        mao2013.setName("La Poule du Tour de France 2013");
        FantasyTour fantasyTour2013 = boundary.makeFantasyTour(mao2013);

        List<FantasyTour> fantasyTours = boundary.findAllFantasyTours();
        assertFalse("Expecting Fantasy Tours to be found, found none", fantasyTours.isEmpty());
        assertTrue("Expecting 3 Fantasy Tours, found " + fantasyTours.size(), fantasyTours.size() == 3);
    }
}
